package com.daokin.service;

import com.daokin.constant.SystemConstant;
import com.daokin.dto.User;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.stereotype.Service;

/**
 *
 */
@Service
public class UserService {

    public User getUserByName(String name) {
        User user=new User();
        user.setUser(name);
        user.setPassword("1");
        return user;
    }

    public User userLogin(User user, String password,
            HttpServletRequest request) throws Exception {
        if (password != null && password.equals(user.getPassword())) {
            HttpSession session = request.getSession();
            user.setPassword("");
            session.setAttribute(SystemConstant.SESSION_USER_KEY, user);
        } else {
            throw new Exception("Email or password incorrect.");
        }
        return user;
    }
}
